package com.xiaokong.changerecord.strategy;

import com.xiaokong.changerecord.annotation.ChangeTag;
import com.xiaokong.changerecord.entity.ChangeForm;
import com.xiaokong.changerecord.entity.ChangeRecord;
import com.xiaokong.changerecord.entity.ChangeTable;
import org.aspectj.lang.ProceedingJoinPoint;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;

/**
 * 变更记录策略
 *
 * @author Hu_bx
 * @date 18:18 2023/9/15
 **/
public interface ChangeRecordStrategy {


    /**
     * 获取变更记录
     *
     * @param id id
     * @return com.jingdianjichi.changerecord.entity.ChangeRecord
     * @author Hu_bx
     * @date 18:19 2023/9/15
     **/
    ChangeRecord getById(Object id);

    /**
     * 生成变更实际详情
     *
     * @param joinPoint  joinPoint
     * @param returnBody returnBody
     * @author Hu_bx
     * @date 15:16 2022/11/10
     **/
    void createChangeDescribe(ProceedingJoinPoint joinPoint, Object returnBody);

    /**
     * 生成变更记录
     *
     * @param joinPoint  joinPoint
     * @param returnBody returnBody
     * @return Obj
     * @author Hu_bx
     * @date 15:16 2022/11/10
     **/
    Object createChangeRecord(ProceedingJoinPoint joinPoint, Object returnBody);


    /**
     * 创建修改表单详情
     *
     * @param changeForm changeForm
     * @param fields     fields
     * @param newBody    newBody
     * @param oldBody    oldBody
     * @author Hu_bx
     * @date 15:12 2022/11/10
     **/
    void createChangeForm(ChangeForm changeForm, Field[] fields, Object newBody, Object oldBody);

    /**
     * 创建修改表格详情
     *
     * @param changeForm changeForm
     * @param newField   newField
     * @param oldField   oldField
     * @param field      field
     * @author Hu_bx
     * @date 15:12 2022/11/10
     **/
    void createChangeTable(ChangeForm changeForm, Object newField, Object oldField, Field field);

    /**
     * 设置新值
     *
     * @param newBody newBody
     * @param oldBody oldBody
     * @param field   field
     * @author Hu_bx
     * @date 10:11 2023/3/17
     **/
    void setFieldNewValue(Object newBody, Object oldBody, Field field);

    /**
     * 创建详情
     *
     * @param childForm childForm
     * @param content   content
     * @author Hu_bx
     * @date 14:26 2022/11/11
     **/
    void createDescribe(ChangeForm childForm, List<String> content);

    /**
     * 创建基础类型字段
     *
     * @param changeForm changeForm
     * @param newField   newField
     * @param oldField   oldField
     * @param field      field
     */
    void createSimpleChangeField(ChangeForm changeForm, Object newField, Object oldField, Field field);

    /**
     * 填充表格参数
     *
     * @param newFieldColl newFieldColl
     * @param oldBodyColl  oldBodyColl
     * @param changeTable  changeTable
     * @author Hu_bx
     * @date 17:28 2022/11/10
     **/
    void putTableField(Collection<?> newFieldColl, Collection<?> oldBodyColl, ChangeTable changeTable);

    /**
     * 填充表格行数
     *
     * @param newFieldColl newFieldColl
     * @param oldBodyColl  oldBodyColl
     * @param changeTable  changeTable
     * @author Hu_bx
     * @date 17:28 2022/11/10
     **/
    void putTableNum(ChangeTable changeTable, Collection<?> newFieldColl,
                     Collection<?> oldBodyColl);


    /**
     * 重置主键id
     *
     * @param field   field
     * @param newBody newBody
     */
    void resetChildNewId(Object newBody, Field field);

    /**
     * 格式化值
     *
     * @param value     value
     * @param changeTag changeTag
     * @param field     field
     * @return java.lang.String
     * @author Hu_bx
     * @date 14:55 2023/9/16
     **/
    String formatValue(Object value, ChangeTag changeTag, Field field);

    /**
     * 获取变更记录实际内容
     *
     * @param id id
     * @return java.util.List<java.lang.String>
     * @author Hu_bx
     * @date 13:35 2023/9/16
     **/
    List<String> getDescribe(String id);


    /**
     * 生成新id，替换旧id
     *
     * @param newBody newBody
     * @param field   field
     * @return Object
     * @author Hu_bx
     * @date 12:17 2023/9/16
     **/
    Object generateId(Object newBody, Field field);

    /**
     * 创建变更详情回调，用于更新
     *
     * @param changeRecord changeRecord
     * @param returnType   returnType
     * @author Hu_bx
     * @date 12:17 2023/9/16
     **/
    void createChangeDescribeCallBack(ChangeRecord changeRecord, Class<?> returnType);

    /**
     * 创建变更记录回调，用于保存
     *
     * @param changeRecord changeRecord
     * @param returnType   returnType
     * @author Hu_bx
     * @date 12:17 2023/9/16
     **/
    void createChangeRecordCallBack(ChangeRecord changeRecord, Class<?> returnType);
}
